package com.jt.system.UserService.impl;

import com.jt.system.UserService.UserService;
import com.jt.system.dao.UserMapper;
import com.jt.system.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Slf4j
@Service
//事物是通过DataSourceTransationManager控制的
@Transactional(readOnly = false)  //只读事物
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    @Transactional(readOnly = true) //事物切入点方法
    public User selectUserByUsername(String username) {
        log.debug("username {}",username);
        return userMapper.selectUserByUsername(username);
    }

    @Override
    //事物切入点
    @Transactional(readOnly = true)
    //缓存切入点
    @Cacheable(value = "userPermissions",key="#userId")
    public List<String> selectUserPermissions(Long userId) {
        log.debug("userId {}",userId);
        return userMapper.selectUserPermissions(userId);
    }

}
